package  
{
	import org.flixel.*;
	
	/**
	 * ...
	 * @author Andrew Tolver
	 */
	public class MovingObjectCirc extends FlxSprite
	{
		private var _circleRadius:Number;		//stores moveable area rectangle
		private var _currentAngle:Number;		//stores the object's current angle
		private var _angleVelocity:Number;		//stores the velocity of the object
		
		/**
		 * Constructor for the moving object
		 * 
		 * @param	image		Image you want to use for the object.
		 * @param	oWidth		Width of the object.
		 * @param	oHeight		Height of the object.
		 */
		public function MovingObjectCirc(image:Class, oWidth:Number, oHeight:Number) 
		{
			super();
			loadGraphic(image, false, false, oWidth, oHeight);
			this.fixed = true;
			this.collideLeft = false;
			this.collideRight = false;
			this.collideBottom = false;
		}
		
		/**
		 * Give the object a starting position.
		 * 
		 * @param	X				Starting X point of the object.
		 * @param	Y				Starting Y point of the object.
		 * @param	startAngle		Starting angular position of the object, in radians.
		 */
		public function setStartPoint( startAngle:Number, X:Number = 0, Y:Number = 0 ):void
		{
			this.x = X;
			this.y = Y;
			_currentAngle = startAngle;
		}
		
		/**
		 * Create a box for the object to patrol
		 * 
		 * @param	pointX			The X-coordinate of the center of the circle the object will rotate around
		 * @param	pointY			The Y-coordinate of the center of the circle the object will rotate around
		 * @param	radius			The radius of the circle
		 */
		public function setCirclingBox(radius:Number):void
		{
			_circleRadius = radius;
		}
		
		/**
		 * Give the object velocity values to move.
		 * 
		 * @param	platformSpeed		The speed of the object.
		 */
		public function setVelocity(platformSpeed:Number):void
		{
			_angleVelocity = platformSpeed;
		}
		
		override public function update():void
		{
			super.update();
			
			_currentAngle += FlxG.elapsed * _angleVelocity;
			
			if (_currentAngle >= 2*Math.PI)
			{
				_currentAngle -= 2*Math.PI;
			}
			
			velocity.x = (Math.cos(_currentAngle) * _circleRadius);
			velocity.y = (Math.sin(_currentAngle) * _circleRadius);
		}
	}

}